module Procesar where
import Data
import Tacticas
import qualified Data.IntSet as IS
--------------------------------------------------------LECTURA Y ESCRITURA ----------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------

readLineSudokuLibres :: Int -> Int -> [Char] -> Libres
readLineSudokuLibres linea col (x:xs)  
	| col == 0 = []
	| x == '0' = ((linea,8-col),IS.fromList [1..9]) : readLineSudokuLibres linea (col-1) xs
	| otherwise = readLineSudokuLibres linea (col-1) xs

readLineSudokuOcupados :: Int -> Int -> [Char] -> Libres
readLineSudokuOcupados linea col (x:xs)  
	| col == 0 = []
	| not (x == '0') = ((linea,8-col),IS.fromList [1..9]) : readLineSudokuOcupados linea (col-1) xs
	| otherwise = readLineSudokuOcupados linea (col-1) xs

showAll :: [String] -> String
showAll xs 
	| xs == [] = ""
	| otherwise = head xs ++ "\n" ++ showAll (tail xs)

showLibres :: Libres -> String
showLibres entrada = showAll[showPosicion p ++ "[" ++ showDigitos (IS.toList d) ++ "]"| (p,d) <- entrada] 

showPosicion :: Posicion -> String
showPosicion p = "(" ++ show (fst p) ++ ","++ show(snd p) ++ ") "

showDigitos :: [Int] -> String
showDigitos (d:xd) 
	|xd == [] = show d
	| otherwise = show d ++ "," ++ showDigitos xd

